using MicroMsg.Common.Event;
using MicroMsg.Manager;
using MicroMsg.Resource.@string;
using MicroMsg.Storage;
using MicroMsg.UI.Page;
using MicroMsg.UI.Util;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Media.Imaging;
namespace MicroMsg.UI.UserContrl
{
	public class ProfileTopInfoCtrl : ProfileInfoItemBase
	{
		public delegate void ListItemClick(object sender, object object_0);
		private const string TAG = "ProfileTopInfoCtrl";
		private const int cNMaxCacheCnt = 1;
		private bool mBIsFirstLoaded = true;
		private EventWatcher mWatchxxx;
		private object mObjectWatcher = new object();
		private static List<ProfileTopInfoCtrl> sItemsCached = new List<ProfileTopInfoCtrl>();
		private Contact mContact;
		internal StackPanel LayoutRoot;
		internal Grid gridHeadBG;
		internal Image imgHead;
		internal Grid gridSexBG;
		internal Image imgSex;
		internal ScrollTextBlock txtNicks;
		internal ClickEffectGrid btnGStart;
		internal Image imgStar;
		internal EmojiText txtRemark;
		internal TextBlock txtID;
		internal StackPanel panelVerifyInfo;
		internal Image imgVerifyInfoCorner;
		internal Border BorderVerifyInfo;
		internal TextBlock txtVerifyInfo;
		internal Button btnRemark;
		internal EmojiTextEx txtSig;
		private bool _contentLoaded;
		public event ProfileTopInfoCtrl.ListItemClick ItemClick;
		public event MMStandardUIEvent mBtnRemarkClick;
		public event MMStandardUIEvent mImgHeadClicked;
		public ProfileTopInfoCtrl()
		{
			this.InitializeComponent();
			base.set_Margin(new Thickness(0.0, 32.0, 0.0, 0.0));
			base.add_Loaded(new RoutedEventHandler(this.Control_Loaded));
			base.add_Unloaded(new RoutedEventHandler(this.Control_Unloaded));
		}
		private void Control_Loaded(object sender, RoutedEventArgs e)
		{
		}
		private void Control_Unloaded(object sender, RoutedEventArgs e)
		{
		}
		private void registerEvent()
		{
			if (this.mWatchxxx == null)
			{
				this.mWatchxxx = new EventWatcher(this.mObjectWatcher, null, new EventHandlerDelegate(this.Onxxx));
				EventCenter.registerEventWatcher(EventConst.ON_STORAGE_CONTACT_ADD, this.mWatchxxx);
			}
		}
		private void unRegisterEvent()
		{
			if (this.mWatchxxx != null)
			{
				EventCenter.removeEventWatcher(EventConst.ON_STORAGE_CONTACT_ADD, this.mWatchxxx);
				this.mWatchxxx = null;
			}
		}
		private void Onxxx(EventWatcher watcher, BaseEventArgs evtArgs)
		{
			if (evtArgs == null)
			{
				return;
			}
		}
		private void btnRemark_Click(object sender, RoutedEventArgs e)
		{
			if (this.mBtnRemarkClick != null)
			{
				this.mBtnRemarkClick(sender, e);
			}
		}
		public void ShowBtnRemark()
		{
			this.btnRemark.set_Visibility(0);
		}
		public void HideBtnRemark()
		{
			this.btnRemark.set_Visibility(1);
		}
		private void btnLayoutRoot_Click(object sender, RoutedEventArgs e)
		{
		}
		private void btnGStart_mClicked(object sender, object args)
		{
			if (this.mContact == null)
			{
				return;
			}
			bool flag = ContactMgr.isFavourContact(this.mContact);
			ContactMgr.operationSetFavourContact(this.mContact, !flag);
			this.ShowStar();
		}
		private void imgHeadClicked(object sender, RoutedEventArgs e)
		{
			if (this.txtID.get_Text() == "filehelper")
			{
				return;
			}
			if (this.mImgHeadClicked != null)
			{
				BasePage rootPage = ToolFunction.GetRootPage();
				if (rootPage != null)
				{
					UIElement arg_32_0 = rootPage.get_Content();
				}
				Point point = default(Point);
				try
				{
					GeneralTransform generalTransform = this.imgHead.TransformToVisual(Application.get_Current().get_RootVisual());
					point = generalTransform.Transform(new Point(0.0, 0.0));
				}
				catch
				{
					return;
				}
				Rect rect = new Rect(point.get_X(), point.get_Y(), this.imgHead.get_ActualWidth(), this.imgHead.get_ActualHeight());
				this.mImgHeadClicked(rect, this.imgHead.get_Source());
			}
		}
		public void SetRemark(string strRemark)
		{
			if (string.IsNullOrEmpty(strRemark))
			{
				this.txtRemark.set_Visibility(1);
				return;
			}
			if (MMTheme.IsCoolBlackTheme())
			{
				EmojiText arg_3F_0 = this.txtRemark;
				SolidColorBrush solidColorBrush = new SolidColorBrush();
				solidColorBrush.set_Color(Color.FromArgb(255, 97, 97, 97));
				arg_3F_0.Foreground = solidColorBrush;
			}
			else
			{
				EmojiText arg_72_0 = this.txtRemark;
				SolidColorBrush solidColorBrush2 = new SolidColorBrush();
				solidColorBrush2.set_Color(Color.FromArgb(255, 139, 139, 139));
				arg_72_0.Foreground = solidColorBrush2;
			}
			this.txtRemark.Text = strings.Con_Detail_TxtRemarkLead + strRemark;
			this.txtRemark.set_Visibility(0);
		}
		public void SetID(string strUsrName, string strAlias = null)
		{
			string text = string.IsNullOrEmpty(strAlias) ? strUsrName : strAlias;
			if (string.IsNullOrEmpty(text))
			{
				this.txtID.set_Text("");
				return;
			}
			if (strUsrName == "filehelper")
			{
				this.gridHeadBG.set_Background(R.theme.COMMON_BRUSH);
			}
			else
			{
				this.gridHeadBG.set_Background(null);
			}
			if (text == "weixin" && R.isEnglish())
			{
				text = strings.COM_MicroMsg;
			}
			if (MMTheme.IsCoolBlackTheme())
			{
				TextBlock arg_9A_0 = this.txtID;
				SolidColorBrush solidColorBrush = new SolidColorBrush();
				solidColorBrush.set_Color(Color.FromArgb(255, 97, 97, 97));
				arg_9A_0.set_Foreground(solidColorBrush);
			}
			else
			{
				TextBlock arg_CD_0 = this.txtID;
				SolidColorBrush solidColorBrush2 = new SolidColorBrush();
				solidColorBrush2.set_Color(Color.FromArgb(255, 139, 139, 139));
				arg_CD_0.set_Foreground(solidColorBrush2);
			}
			this.txtID.set_Text(string.Format(strings.FMsgWeiXinId, text));
		}
		public void SetSex(int nSex)
		{
			if (1 == nSex)
			{
				this.gridSexBG.set_Visibility(0);
				this.imgSex.set_Source(ImageCacheMgr.loadFromRes(MMTheme.GetInstance().sexIcon_man));
				return;
			}
			if (2 == nSex)
			{
				this.gridSexBG.set_Visibility(0);
				this.imgSex.set_Source(ImageCacheMgr.loadFromRes(MMTheme.GetInstance().sexIcon_woman));
				return;
			}
			this.gridSexBG.set_Visibility(1);
		}
		public void SetSayHiContent(string strHi)
		{
		}
		public void SetRequestStr(string strRequest)
		{
			if (string.IsNullOrEmpty(strRequest))
			{
				this.panelVerifyInfo.set_Visibility(1);
				return;
			}
			this.panelVerifyInfo.set_Visibility(0);
			this.txtVerifyInfo.set_Text(strRequest);
		}
		public void SetSignature(string strSig)
		{
			if (string.IsNullOrEmpty(strSig))
			{
				this.txtSig.set_Visibility(1);
				return;
			}
			this.txtSig.set_Visibility(0);
			this.txtSig.Text = strSig;
		}
		public override void Collect()
		{
			this.SetSex(0);
			this.SetVerifyInfo(null);
			this.SetID("", null);
			this.SetRequestStr("");
			this.SetRemark(null);
			this.txtSig.set_Visibility(1);
			this.SetContact(null);
			this.HideStar();
			this.HideBtnRemark();
		}
		public void SetVerifyInfo(BitmapImage bitmapImage_0)
		{
		}
		protected override void RefreshItem()
		{
			if (base.InfoData == null)
			{
				return;
			}
			this.txtNicks.Text = base.InfoData.mStrTitle;
			this.txtSig.Text = base.InfoData.mStrInfo1;
			this.txtSig.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
			this.txtSig.InvalidateMeasure();
			this.txtSig.set_Height(this.txtSig.get_DesiredSize().get_Height());
			this.txtSig.UpdateLayout();
			this.imgHead.set_Source(base.InfoData.mBitMapImg);
			if (1 == base.InfoData.mNSex)
			{
				this.imgSex.set_Visibility(0);
				this.imgSex.set_Source(new BitmapImage(new Uri("/Resource/Img/CommonUse/SexIco_man.png", 2)));
			}
			else
			{
				if (2 == base.InfoData.mNSex)
				{
					this.imgSex.set_Visibility(0);
					this.imgSex.set_Source(new BitmapImage(new Uri("/Resource/Img/CommonUse/SexIco_woman.png", 2)));
				}
				else
				{
					this.imgSex.set_Visibility(1);
				}
			}
			base.UpdateLayout();
		}
		public static ProfileTopInfoCtrl GetOneItem()
		{
			if (ProfileTopInfoCtrl.sItemsCached != null && ProfileTopInfoCtrl.sItemsCached.get_Count() != 0)
			{
				ProfileTopInfoCtrl profileTopInfoCtrl = Enumerable.First<ProfileTopInfoCtrl>(ProfileTopInfoCtrl.sItemsCached);
				ProfileTopInfoCtrl.sItemsCached.RemoveAt(0);
				if (profileTopInfoCtrl.get_Parent() == null)
				{
					profileTopInfoCtrl.set_Visibility(0);
					return profileTopInfoCtrl;
				}
			}
			return new ProfileTopInfoCtrl();
		}
		public static int GetCacheCnt()
		{
			if (ProfileTopInfoCtrl.sItemsCached == null)
			{
				return 0;
			}
			return ProfileTopInfoCtrl.sItemsCached.get_Count();
		}
		public static void PushOneItem(ProfileTopInfoCtrl item)
		{
			if (item == null)
			{
				return;
			}
			if (ProfileTopInfoCtrl.sItemsCached == null)
			{
				ProfileTopInfoCtrl.sItemsCached = new List<ProfileTopInfoCtrl>();
			}
			if (item.get_Parent() != null)
			{
				Panel panel = item.get_Parent() as Panel;
				if (panel != null)
				{
					panel.get_Children().Remove(item);
				}
			}
			item.Collect();
			if (ProfileTopInfoCtrl.sItemsCached.get_Count() >= 1)
			{
				return;
			}
			ProfileTopInfoCtrl.sItemsCached.Add(item);
		}
		public void SetContact(Contact contact_0)
		{
			this.mContact = contact_0;
		}
		public void ShowStar()
		{
			if (this.mContact == null)
			{
				return;
			}
			if (this.mContact.strUsrName == "filehelper")
			{
				this.btnGStart.set_Visibility(1);
				return;
			}
			this.btnGStart.set_Visibility(0);
			bool flag = ContactMgr.isFavourContact(this.mContact);
			string strPath;
			if (flag)
			{
				strPath = "/Resource/Img/Profile/Stared.png";
			}
			else
			{
				strPath = "/Resource/Img/Profile/UnStared.png";
			}
			this.imgStar.set_Source(ToolFunction.GetImgFromContentSource(strPath));
		}
		public void HideStar()
		{
			this.btnGStart.set_Visibility(1);
		}
		[DebuggerNonUserCode]
		public void InitializeComponent()
		{
			if (this._contentLoaded)
			{
				return;
			}
			this._contentLoaded = true;
			Application.LoadComponent(this, new Uri("/MicroMsg;component/Source/UI/Contact/ProfileInfo/ProfileTopInfoCtrl.xaml", 2));
			this.LayoutRoot = (StackPanel)base.FindName("LayoutRoot");
			this.gridHeadBG = (Grid)base.FindName("gridHeadBG");
			this.imgHead = (Image)base.FindName("imgHead");
			this.gridSexBG = (Grid)base.FindName("gridSexBG");
			this.imgSex = (Image)base.FindName("imgSex");
			this.txtNicks = (ScrollTextBlock)base.FindName("txtNicks");
			this.btnGStart = (ClickEffectGrid)base.FindName("btnGStart");
			this.imgStar = (Image)base.FindName("imgStar");
			this.txtRemark = (EmojiText)base.FindName("txtRemark");
			this.txtID = (TextBlock)base.FindName("txtID");
			this.panelVerifyInfo = (StackPanel)base.FindName("panelVerifyInfo");
			this.imgVerifyInfoCorner = (Image)base.FindName("imgVerifyInfoCorner");
			this.BorderVerifyInfo = (Border)base.FindName("BorderVerifyInfo");
			this.txtVerifyInfo = (TextBlock)base.FindName("txtVerifyInfo");
			this.btnRemark = (Button)base.FindName("btnRemark");
			this.txtSig = (EmojiTextEx)base.FindName("txtSig");
		}
	}
}
